#!/usr/bin/env python
# encoding: utf-8

from app import db

class User(db.Model):
    __tablename__ = 'user'

    id           = db.Column(db.BigInteger, primary_key=True)
    nickname     = db.Column(db.String(100))
    mobile       = db.Column(db.String(20))
    email        = db.Column(db.String(100))
    sex          = db.Column(db.Integer)
    avatar       = db.Column(db.String(200))
    roles        = db.Column(db.String(100))
    introduction = db.Column(db.String(100))
    login_name   = db.Column(db.String(20))
    login_pwd    = db.Column(db.String(32))
    login_salt   = db.Column(db.String(32))
    status       = db.Column(db.Integer)
    updated_time = db.Column(db.DateTime)
    created_time = db.Column(db.DateTime)


class Electronic(db.Model):
    '''元器件表'''
    __tablename__ = 'electronic'

    id           = db.Column(db.BigInteger, primary_key=True)
    name         = db.Column(db.String(100)) # 名称
    sn           = db.Column(db.String(40)) # 编号
    package      = db.Column(db.String(100)) # 封装
    price        = db.Column(db.Numeric(10, 4)) # 单价
    spec         = db.Column(db.String(10)) # 规格
    stock        = db.Column(db.Integer) # 库存数
    position     = db.Column(db.String(50)) # 存放位置
    image_url    = db.Column(db.String(200)) # 图片
    status       = db.Column(db.Integer) # 状态：1:未删除 2:已删除
    supplier     = db.Column(db.String(200)) # 供货商
    delivery     = db.Column(db.String(50)) # 货期
    project      = db.Column(db.String(100)) # 项目产品
    remark       = db.Column(db.String(100)) # 备注

    updated_time  = db.Column(db.DateTime)
    created_time  = db.Column(db.DateTime)

class ElectronicLog(db.Model):
    '''元器件表'''
    __tablename__ = 'electronic_log'

    id            = db.Column(db.BigInteger, primary_key=True)
    electronic_id = db.Column(db.Integer) # 元器件id

    # 出库用的
    operater_id   = db.Column(db.Integer) # 操作人员
    receiver      = db.Column(db.String(30)) # 领用人员

    status        = db.Column(db.Integer) # 状态: 已经打印

    type          = db.Column(db.Integer) # 日志类型: 1: 入库 2: 出库 3: 采购
    count         = db.Column(db.Integer) # 数量
    note          = db.Column(db.String(100)) # 备注
    created_time  = db.Column(db.DateTime)

class ElectronicBoom(db.Model):
    '''元器件boom单'''
    __tablename__ = 'electronic_boom'

    id           = db.Column(db.BigInteger, primary_key=True)
    user_id      = db.Column(db.Integer) # 用户id
    name         = db.Column(db.String(100))
    note         = db.Column(db.String(100)) # 备注信息

    updated_time = db.Column(db.DateTime)
    created_time = db.Column(db.DateTime)

class ElectronicBoomItem(db.Model):
    '''元器件boom单详情'''
    __tablename__ = 'electronic_boom_item'

    id                 = db.Column(db.BigInteger, primary_key=True)
    user_id            = db.Column(db.Integer) # 用户id
    electronic_id      = db.Column(db.Integer) # 元器件id
    electronic_boom_id = db.Column(db.Integer) # 元器件收藏id
    count              = db.Column(db.Integer) # 数量


class ElectronicOrder(db.Model):
    """元器件出库订单表
    type:
        1:入库:
            -1: 取消订单 11: 下单 12: 审核 13:完成订单 -2:审核未通过
        2:出库:
            -1: 取消订单 21: 下单 22: 审核 23:完成订单 -2:审核未通过
        3:采购:
            -1: 取消订单 31: 下单 32: 审核 33: 出库 34: 完成 -2:审核未通过
    """
    __tablename__ = 'electronic_order'

    id      = db.Column(db.BigInteger, primary_key=True)
    type    = db.Column(db.Integer) # 订单类型:  1: 入库    2:出库  3: 采购
    sn      = db.Column(db.String(40)) # 随机订单号
    # 订单状态:  0: 已关闭
    # 1:  提交订单   2: 库管发货 3: 确认收货 4: 完成评价,
    # 5:  采购完成
    # 6:  入库完成
    status  = db.Column(db.Integer)
    step    = db.Column(db.Integer) # 订单进度:  0: 无效    1:有效
    note    = db.Column(db.String(100)) # 备注信息

    project = db.Column(db.String(100)) # 订单项目
    user_id = db.Column(db.Integer) # 下单人id
    checker_id = db.Column(db.Integer) # 审核人id

    updated_time   = db.Column(db.DateTime)
    created_time   = db.Column(db.DateTime)

class ElectronicOrderItem(db.Model):
    """元器件出库订单详情表"""
    __tablename__ = 'electronic_order_item'

    id                  = db.Column(db.BigInteger, primary_key=True)
    user_id             = db.Column(db.Integer) # 用户id
    electronic_id       = db.Column(db.Integer) # 元器件id
    electronic_order_id = db.Column(db.Integer) # 所属订单id
    count               = db.Column(db.Integer) # 出库数量
    note                = db.Column(db.String(100)) # 备注信息

    updated_time  = db.Column(db.DateTime)
    created_time  = db.Column(db.DateTime)

class ElectronicOrderLog(db.Model):
    """元器件订单操作记录"""
    __tablename__ = 'electronic_order_log'

    id                  = db.Column(db.BigInteger, primary_key=True)
    user_id             = db.Column(db.Integer) # 操作人员
    electronic_order_id = db.Column(db.Integer) # 所属订单id
    log                 = db.Column(db.String(100)) # 操作说明
    status              = db.Column(db.Integer) # 订单状态
    updated_time        = db.Column(db.DateTime)
    created_time        = db.Column(db.DateTime)


class ElectronicFavorite(db.Model):
    '''元器件收藏夹'''
    __tablename__ = 'electronic_favorite'

    id           = db.Column(db.BigInteger, primary_key=True)
    user_id      = db.Column(db.Integer) # 用户id
    name         = db.Column(db.String(100))

    updated_time = db.Column(db.DateTime)
    created_time = db.Column(db.DateTime)

class ElectronicFavoriteItem(db.Model):
    '''元器件收藏夹'''
    __tablename__ = 'electronic_favorite_item'

    id                     = db.Column(db.BigInteger, primary_key=True)
    user_id                = db.Column(db.Integer) # 用户id
    electronic_id          = db.Column(db.Integer) # 元器件id
    electronic_favorite_id = db.Column(db.Integer) # 元器件收藏id
    count                  = db.Column(db.Integer) # 数量
    status                 = db.Column(db.Integer) # 0: 未分类，1：已分类

    updated_time           = db.Column(db.DateTime)
    created_time           = db.Column(db.DateTime)




# 旧版本元器件库
class oldComponent(db.Model):
    '''元器件'''
    __tablename__ = 'component'
    __bind_key__ = 'old'

    id         = db.Column(db.Integer,primary_key=True)
    number     = db.Column(db.String(50))
    package    = db.Column(db.String(50))
    parttype   = db.Column(db.String(50))
    price      = db.Column(db.String(50))
    unit       = db.Column(db.String(50))
    count      = db.Column(db.Integer)
    position   = db.Column(db.String(20))
    barcode    = db.Column(db.String(30),unique=True)
    manufacturer = db.Column(db.String(200))
    remark     = db.Column(db.String(200))
    buy_link = db.Column(db.String(200))
    buy_link_lg = db.Column(db.Text(2000))

    project_id         = db.Column(db.Integer)

class oldComponentIn(db.Model):
    __tablename__ = 'component_in'
    __bind_key__ = 'old'
    id        = db.Column(db.Integer,primary_key=True)
    component_id = db.Column(db.Integer)
    instocker_id = db.Column(db.Integer)
    count = db.Column(db.Integer)
    time = db.Column(db.DateTime)
    remark = db.Column(db.String(200))

class oldComponentOut(db.Model):
    __tablename__ = 'component_out'
    __bind_key__ = 'old'
    id            = db.Column(db.Integer,primary_key=True)
    component_id  = db.Column(db.Integer)
    outstocker_id = db.Column(db.Integer)
    receiver_id   = db.Column(db.Integer)
    print_flag    = db.Column(db.Boolean)
    count         = db.Column(db.Integer)
    time          = db.Column(db.DateTime)
    recv          = db.Column(db.String(20))
    remark        = db.Column(db.String(200))

class oldProject(db.Model):
    '''项目表'''
    __tablename__ = 'project'
    __bind_key__ = 'old'
    id           = db.Column(db.Integer,primary_key=True)
    name         = db.Column(db.String(50),unique=True)

class oldProduct(db.Model):
    '''项目表'''
    __tablename__ = 'product'
    __bind_key__ = 'old'
    id           = db.Column(db.Integer,primary_key=True)
    name         = db.Column(db.String(50),unique=True)

class oldUserProductBoard(db.Model):
    '''用户产品模板'''
    __tablename__ = 'user_product_board'
    __bind_key__ = 'old'
    id         = db.Column(db.Integer,primary_key=True)
    name       = db.Column(db.String(100))
    user_id    = db.Column(db.Integer)
    product_id = db.Column(db.Integer)

class oldProductBoard(db.Model):
    '''产品模板所需各元器件数量'''
    __tablename__ = 'product_board'
    __bind_key__ = 'old'
    id           = db.Column(db.Integer,primary_key=True)
    count        = db.Column(db.Integer)
    board_id     = db.Column(db.Integer)
    component_id = db.Column(db.Integer)


